#include "ManagedLasoProvider.h"

/* Table of constant values */

static integer c__1 = 1;


/* ------------------------------------------------------------------ */

 /* Subroutine */int SmartMathLibrary::LasoPack::ManagedLasoProvider::dmvpc_
   (integer *nblock, doublereal *bet, integer *maxj, integer *j, doublereal *s,
   integer *number, doublereal *resnrm, doublereal *orthcf, doublereal *rv)
{
  /* System generated locals */
  integer bet_dim1, bet_offset, s_dim1, s_offset, i__1, i__2;
  doublereal d__1, d__2, d__3;

  /* Local variables */
  /* extern doublereal ddot_(integer *, doublereal *, integer *, doublereal *, 
  integer *), dnrm2_(integer *, doublereal *, integer *);*/
  static integer i__, k, m;



  /* THIS SUBROUTINE COMPUTES THE NORM AND THE SMALLEST ELEMENT */
  /* (IN ABSOLUTE VALUE) OF THE VECTOR BET*SJI, WHERE SJI */
  /* IS AN NBLOCK VECTOR OF THE LAST NBLOCK ELEMENTS OF THE ITH */
  /* EIGENVECTOR OF T.  THESE QUANTITIES ARE THE RESIDUAL NORM */
  /* AND THE ORTHOGONALITY COEFFICIENT RESPECTIVELY FOR THE */
  /* CORRESPONDING RITZ PAIR.  THE ORTHOGONALITY COEFFICIENT IS */
  /* NORMALIZED TO ACCOUNT FOR THE LOCAL REORTHOGONALIZATION. */


  /* Parameter adjustments */
  bet_dim1 =  *nblock;
  bet_offset = 1+bet_dim1 * 1;
  bet -= bet_offset;
  s_dim1 =  *maxj;
  s_offset = 1+s_dim1 * 1;
  s -= s_offset;
  --resnrm;
  --orthcf;
  --rv;

  /* Function Body */
  m =  *j -  *nblock + 1;
  i__1 =  *number;
  for (i__ = 1; i__ <= i__1; ++i__)
  {
    i__2 =  *nblock;
    for (k = 1; k <= i__2; ++k)
    {
      rv[k] = ddot_(nblock, &s[m + i__ * s_dim1], &c__1, &bet[k + bet_dim1],
        nblock);
      if (k == 1)
      {
        orthcf[i__] = (d__1 = rv[k], abs(d__1));
      }
      /* Computing MIN */
      d__2 = orthcf[i__], d__3 = (d__1 = rv[k], abs(d__1));
      orthcf[i__] = min(d__2, d__3);
      /* L10: */
    }
    resnrm[i__] = dnrm2_(nblock, &rv[1], &c__1);
    /* L20: */
  }
  return 0;
} /* dmvpc_ */
